﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SpaceSquirrel.Automation
{
	public class LavaMonsterAutomation : SpriteAutomation
	{
		private const int RISE_SPEED = 1;
		private const int WAIT_INTERVAL = 30 * 4;

		private int counter = 0;
		private string mode = "wait";
		public bool mouthOpen = false;

		public LavaMonsterAutomation(Sprite sprite)
			: base(sprite)
		{ }

		public override void DoStuff(PlayScene scene)
		{
			++this.counter;
			this.mouthOpen = false;
			bool faceLeft = scene.Player.x < this.sprite.x;
			this.sprite.lastDirection = faceLeft ? "left" : "right";
			if (this.mode == "wait")
			{
				if (this.counter == WAIT_INTERVAL)
				{
					this.counter = 0;
					this.mode = "rise";
				}
			}
			else if (this.mode == "rise")
			{
				if (this.counter == 16)
				{
					this.mode = "shoot";
					this.counter = 0;
				}
				this.sprite.dy = -1;
			}
			else if (this.mode == "shoot")
			{
				if (this.counter == 60)
				{
					this.mode = "fall";
					this.counter = 0;
				}
				if (this.counter == 7)
				{
					this.CreateFireBall();
				}
				if (this.counter > 0 && this.counter < 14)
				{
					this.mouthOpen = true;
				}
			}
			else if (this.mode == "fall")
			{
				if (this.counter == 16)
				{
					this.mode = "wait";
					this.counter = 0;
				}
				this.sprite.dy = 1;
			}
		}

		private void CreateFireBall()
		{
			Sprite fireball = new Sprite("fireball", this.sprite.x, this.sprite.y);
			this.sprite.spawns = new List<Sprite>() { fireball };
		}
	}
}
